package pl.wroc.uni.ii.evolution.sampleimplementation.comparision;

import pl.wroc.uni.ii.evolution.engine.EvPopulation;
import pl.wroc.uni.ii.evolution.engine.individuals.EvBinaryVectorIndividual;
import pl.wroc.uni.ii.evolution.engine.operators.general.selections.EvTournamentSelection;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.sboa.EvBayesianNetwork;
import pl.wroc.uni.ii.evolution.engine.operators.spacespecific.binaryvector.sboa.EvBoaStrategy;
import pl.wroc.uni.ii.evolution.objectivefunctions.Ev3Deceptive;
import pl.wroc.uni.ii.evolution.solutionspaces.EvBinaryVectorSpace;

public class EvSBOAStrategyBench  {

  public static void main(String[] args) {
   
    int d = 2 * 21;
    int k = 2;
    int n = 5000;
    
    EvBinaryVectorSpace space = new EvBinaryVectorSpace(new Ev3Deceptive(), d);
    EvPopulation<EvBinaryVectorIndividual> population = new EvPopulation<EvBinaryVectorIndividual>();
  
    for (int i = 0; i < n; i++) {
      population.add(space.generateIndividual());
    }
  
    EvTournamentSelection<EvBinaryVectorIndividual> selection = new EvTournamentSelection<EvBinaryVectorIndividual>(16, 4);
    population = selection.apply(population);
    
    EvBoaStrategy strategy = new EvBoaStrategy();
    strategy.init( population.size() + 1, 2);
    EvBayesianNetwork net = new EvBayesianNetwork(d, k);
    
    long start = System.currentTimeMillis();
    strategy.model(population, net);
    long end = System.currentTimeMillis();
    
    System.out.println( (end - start) + " ms");
    
    System.out.println("Edges: " + net.getNumberOfEdges());
   
    //System.out.println(net);
    
    EvBinaryVectorIndividual[] pop = population.toArray(new EvBinaryVectorIndividual[population.size()]);
    
    start = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
      
      net.generate(pop);
    }
   
    end = System.currentTimeMillis();
    
    System.out.println(end - start + "ms");
    
  }

}
